3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
Size fields appear only in binary metafiles. They specify the size (i.e. the extent) of an object, and so determine its end. In a text file, the extent of an object is determined by parentheses; ( specifies its beginning and ) its end. Here's an example of a text file:
Polygon ( # object type
3 # number of vertices
0 0 0 # first vertex
1 0 0 # second vertex
0 1 0 # third vertex
)
This polygon can be viewed as a structure having two fields. The value in the first field is an unsigned 32-bit integer and the value in the second field is an array of three three-dimensional points. The size of an unsigned 32-bit integer is 4 bytes and the size of a three-dimensional point is 12 bytes, so the size of the above polygon is 40 bytes.
In a binary file, an object specification begins with a 4-byte type code. That is immediately followed by 4 bytes that specify the size of the object. The size does not include the 4-byte type code, nor the 4-byte size specification itself. Thus, the size of the above polygon is 40 bytes, not 44 or 48.
The above polygon would be specified in a binary file as follows:
00: 706C6967 plyg # object type
04: 00000028 40 # object size
08: 00000003 3 # number of vertices
0A: 00000000 0.0 # x coordinate of first vertex
10: 00000000 0.0 # y coordinate of first vertex
14: 00000000 0.0 # z coordinate of first vertex
18: 3F800000 1.0 # x coordinate of second vertex
.
.
An object may be of size 0. In a text file, an object of size 0 is described by the type-identifying string followed by a pair of empty parentheses. For example, AttributeSet ( ) specifies an object of size 0. Some objects have a defined default specification. If such an object is represented as being of size 0, it is understood that the default specification is intended. A binary metafile object of size 0 consists of its 4-byte type ID, followed by the 4-byte size specification (which has value 0) and nothing else.
All binary metafile objects are padded to 4-byte boundaries; thus, the size of an object is always a multiple of 4.
Previous | QD3D Book | Overview | Chapter Contents | Next |